package com.example.dllo.keepdemo.dynamic;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.example.dllo.keepdemo.main.MainActivity;
import com.example.dllo.keepdemo.R;
import com.example.dllo.keepdemo.base.BaseFragment;
import com.example.dllo.keepdemo.dynamic.attention.AttentionFragment;
import com.example.dllo.keepdemo.dynamic.find.FindFragment;
import com.example.dllo.keepdemo.dynamic.latest.LatestFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by dllo on 16/1/8.
 * 动态
 */
public class DynamicFragment extends BaseFragment {
    private ArrayList<Fragment> data;
    private ViewPager viewPager;
    private TabLayout tabLayout;
    private DynamicViewPagerAdapter myAdapter;
    private Toolbar toolbar;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dynamic,container,false);
        toolbar = (Toolbar) view.findViewById(R.id.toolbar_fragment_dynamic);
        viewPager = (ViewPager) view.findViewById(R.id.viewpager_fragment_dynamic);
        tabLayout = (TabLayout) view.findViewById(R.id.tablayout_fragment_dynamic);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        toolbar.setTitle("");
        ((MainActivity)getActivity()).setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.mipmap.newslight);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toast("消息");
            }
        });

        data = new ArrayList<>();
        data.add(new FindFragment());
        data.add(new AttentionFragment());
        data.add(new LatestFragment());
        myAdapter = new DynamicViewPagerAdapter(getActivity().getSupportFragmentManager(),data,getActivity());

        viewPager.setAdapter(myAdapter);
        tabLayout.setTabTextColors(Color.parseColor("#C6C5CC"), Color.parseColor("#FFFFFF"));
        tabLayout.setupWithViewPager(viewPager);
//        tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#584F60"));

        setHasOptionsMenu(true);
    }

    //menu
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        getActivity().getMenuInflater().inflate(R.menu.menu_fragment_dynamic,menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_send_fragment_dynamic :
                toast("发动态");
                break;
        }
        return true;
    }

}
